import request from '@/utils/request'

// 查询器具列表
export function listContainer(query) {
  return request({
    url: '/pack/container/list',
    method: 'get',
    params: query
  })
}

// 查询器具详细
export function getContainer(containerId) {
  return request({
    url: '/pack/container/' + containerId,
    method: 'get'
  })
}

// 新增器具
export function addContainer(data) {
  return request({
    url: '/pack/container',
    method: 'post',
    data: data
  })
}

// 修改器具
export function updateContainer(data) {
  return request({
    url: '/pack/container/' + data.containerId,
    method: 'put',
    data: data
  })
}

// 删除器具
export function delContainer(containerId) {
  return request({
    url: '/pack/container/' + containerId,
    method: 'delete'
  })
}

// 器具绑定定位器
export function bindLocator(containerId, locatorId) {
  return request({
    url: '/pack/container/' + containerId + '/bind-locator',
    method: 'post',
    data: { locatorId: locatorId }
  })
}

// 器具解绑定位器
export function unbindLocator(containerId) {
  return request({
    url: '/pack/container/' + containerId + '/unbind-locator',
    method: 'post'
  })
}

// 器具批量绑定定位器
export function batchBindLocators(containerId, locatorIds) {
  return request({
    url: '/pack/container/' + containerId + '/batch-bind-locators',
    method: 'post',
    data: { locatorIds: locatorIds }
  })
}

// 器具状态变更
export function updateContainerStatus(containerId, data) {
  return request({
    url: '/pack/container/' + containerId + '/status',
    method: 'put',
    data: data
  })
}

// 导出器具数据
export function exportContainer(query) {
  return request({
    url: '/pack/container/export',
    method: 'post',
    params: query
  })
}

// 查询定位器列表（用于绑定选择）
export function listLocatorForBind(query) {
  return request({
    url: '/pack/locator/list',
    method: 'get',
    params: query
  })
}

// 注意：listWarehouse 和 listProject 已移至各自的 API 文件中
// import { listWarehouse } from '@/api/pack/warehouse'
// import { listProject } from '@/api/pack/project'

// 校验器具编码是否唯一
export function checkContainerCodeUnique(containerCode) {
  return request({
    url: '/pack/container/checkContainerCodeUnique',
    method: 'post',
    data: { containerCode: containerCode }
  })
}

// 获取器具列表用于定位器选择
export function listContainerForLocator(query) {
  return request({
    url: '/pack/container/list-for-locator',
    method: 'get',
    params: query
  })
}

// 获取项目的物料列表（器具信息）
export function getProjectMaterials(projectId) {
  return request({
    url: '/pack/project/' + projectId + '/materials',
    method: 'get'
  })
}

// 获取项目关联的仓库列表
export function getProjectWarehouses(projectId) {
  return request({
    url: '/pack/project/' + projectId + '/warehouse/operation/list',
    method: 'get'
  })
}

// 器具汇总统计查询
export function getContainerSummary(query) {
  return request({
    url: '/pack/container/summary',
    method: 'get',
    params: query
  })
}

// 获取器具汇总详情列表
export function getContainerSummaryDetail(query) {
  return request({
    url: '/pack/container/summary/detail',
    method: 'get',
    params: query
  })
}

// 获取器具移动记录
export function getContainerTransferRecords(containerId, query) {
  return request({
    url: '/pack/container/' + containerId + '/transfer-records',
    method: 'get',
    params: query
  })
}
